package com.example.demo;

import com.example.demo.mybatisplus.CodeGenConfig;
import com.example.demo.mybatisplus.CodeGeneratorService;
import com.example.demo.util.TemplateEngineUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Map;

@SpringBootApplication
public class Demo1Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
        try {
            // 创建配置
            CodeGenConfig config = new CodeGenConfig();

            // 初始化模板引擎和代码生成服务
            TemplateEngineUtil templateEngine = new TemplateEngineUtil();
            CodeGeneratorService generator = new CodeGeneratorService(templateEngine);

            // 生成代码
            Map<String, String> generatedCode = generator.generateCode(config);

            // 保存生成的代码到文件
            generator.saveGeneratedFiles(generatedCode, "com/example/demo/");

            System.out.println("代码生成完成！生成的文件位于 output/ 目录下。");
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("代码生成失败: " + e.getMessage());
        }
    }

}
